package cn.com.thinker.core.module.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.annotations.Version;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.NotEmpty;
//import org.hibernate.annotations.GenericGenerator;

//import javax.persistence.Entity;
//import javax.persistence.GeneratedValue;
//import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

/**
 * 用户表
 */
@EqualsAndHashCode(callSuper = true)
@Data @NoArgsConstructor @AllArgsConstructor
@Entity @Table(name = "sys_user") @TableName("sys_user")
public class User extends Model<User> {

    /** 主键ID */
    @Id @TableId(value = "id")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @GeneratedValue(generator="uuid")
    private String id;

    /** 名称 */
    /**
     * @size(min=3,max=20,message="用户名长度只能在3-20之间")
     * @size(min=6,max=20,message="密码长度只能在6-20之间")
     * @pattern(regexp="[a-za-z0-9._%+-]+@[a-za-z0-9.-]+\\.[a-za-z]{2,4}", message="邮件格式错误")
     * @Length(min=5, max = 20, message = "用户名长度必须位于5到20之间")
     * @Email(message="比如输入正确的邮箱")
     * @NotNull(message = "用户名称不能为空")
     * @Max(value = 100, message = "年龄不能大于100岁")
     * @Min(value= 18 ,message= "必须年满18岁！" )
     * @AssertTrue(message = "bln4 must is true")
     * @AssertFalse(message = "blnf must is falase")
     * @DecimalMax(value="100",message="decim最大值是100")
     * @DecimalMin(value="100",message="decim最小值是100")
     * @Pattern(regexp="^(\\d{18,18}|\\d{15,15}|(\\d{17,17}[x|X]))$", message="身份证格式错误")
     * 在controller参数添加@Valid修饰ben,后面跟BindingResult result获取验证结果
     */
    @NotEmpty(message="姓名不能为空")
    private String name;

    @TableField(value = "create_time")
    private Date createTime;

    public User(String name) {
        this.name = name;
    }

    @Override
    protected Serializable pkVal() {
        return id;
    }

}
